package com.minelx.treeftp;

import com.minelx.landisk.filesystem.stringnify.PathNavigator;

import java.io.ByteArrayOutputStream;
import java.io.OutputStream;

public class TreeFile {
	private final FileClient client;

	private final PathNavigator navigator;

	public TreeFile(String path, FileClient client) {
		this.client = client;
		navigator = PathNavigator.pathAt(path);
	}

	public void read(OutputStream output) {
		client.read(output, navigator.toPathText());
	}

	public String readAsText() {
		ByteArrayOutputStream output = new ByteArrayOutputStream();
		read(output);
		return output.toString();
	}

	public String getName() {
		return navigator.currentFileName();
	}

	@Override
	public String toString() {
		return getName();
	}
}
